package com.xnyzc.lhy.task.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @Description:
 * @Author: scootXin
 * @Date: 2019/4/24 15:00
 */
@Configuration
public class ThreadPoolConfiguration {

    private final int CORE_POOL_SIZE = 4;
    private final int MAX_POOL_SIZE = 32;
    private final int QUEUE_SIZE = 1000;

    @Bean(name = "taskExecutor")
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
        //线程池维护线程的最少数量
        poolTaskExecutor.setCorePoolSize(CORE_POOL_SIZE);
        //线程池维护线程的最大数量
        poolTaskExecutor.setMaxPoolSize(MAX_POOL_SIZE);
        //线程池所使用的缓冲队列
        poolTaskExecutor.setQueueCapacity(QUEUE_SIZE);
        //线程池维护线程所允许的空闲时间
        poolTaskExecutor.setKeepAliveSeconds(60000);

        poolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);
        return poolTaskExecutor;
    }
}
